//
//  XZRoomNameCell.m
//  Teecloud
//
//  Created by PC on 2018/11/19.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZRoomNameCell.h"
#import "XZMemberList.h"
@interface XZRoomNameCell ()
@property (weak, nonatomic) IBOutlet UIImageView *HeadImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *sexLabel;
//装按钮的view
@property (weak, nonatomic) IBOutlet UIView *bgView;
@end

@implementation XZRoomNameCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(XZMemberList *)model{
    _model = model;
    //将其bgView中的按钮全部移除掉
    [self.bgView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.HeadImg yy_setImageWithURL:[NSURL URLWithString:model.HeadUrl] placeholder:[UIImage imageNamed:@"big_icon"]];
    self.nameLabel.text = model.Name;
    self.sexLabel.text = model.Sex;
    
    /*************根据不同的状体来显示不同的按钮************/
    
    if (!kIsEmptyString(model.ClockStatusName)) {
        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn1 setTitle:model.ClockStatusName forState:UIControlStateNormal];
        [btn1 setBackgroundColor:kWhiteColor];
        btn1.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
        btn1.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:btn1];
        [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(18);
            make.left.mas_equalTo(self.bgView).offset(4);
            make.centerY.mas_equalTo(self.bgView);
        }];
        if ([model.ClockStatusName isEqualToString:@"请假"]) {
            [btn1 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [btn1 setBackgroundColor:kFF8700Color];
            //请假
            if ([model.ClockStatus isEqualToString:@"5"]) {
                [btn1 addTarget:self action:@selector(btn1ApplyAction) forControlEvents:UIControlEventTouchUpInside];
            }
        }else if ([model.ClockStatusName isEqualToString:@"正常"]){
            [btn1 setTitleColor:k1168E6Color forState:UIControlStateNormal];
            btn1.layer.borderWidth = 0.5f;
            btn1.layer.borderColor = k1168E6Color.CGColor;
            
        }else if ([model.ClockStatusName isEqualToString:@"缺卡"]){
            [btn1 setTitleColor:kRedColor forState:UIControlStateNormal];
            btn1.layer.borderWidth = 0.5f;
            btn1.layer.borderColor = kRedColor.CGColor;
        }else if ([model.ClockStatusName isEqualToString:@"迟到"] || [model.ClockStatusName isEqualToString:@"早退"]){
            [btn1 setTitleColor:kFF8700Color forState:UIControlStateNormal];
            btn1.layer.borderWidth = 0.5f;
            btn1.layer.borderColor = kFF8700Color.CGColor;
        }
    }
    
    
    if (!kIsEmptyString(model.NamingStatusName)) {
        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn1 setBackgroundColor:kWhiteColor];
        [btn1 setTitle:model.NamingStatusName forState:UIControlStateNormal];
        btn1.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
        btn1.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:btn1];
        [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(18);
            make.right.mas_equalTo(self.bgView).offset(-4);
            make.centerY.mas_equalTo(self.bgView);
        }];
        if ([model.NamingStatusName isEqualToString:@"请假"]) {
            [btn1 setTitleColor:kFF8700Color forState:UIControlStateNormal];
            btn1.layer.borderWidth = 0.5f;
            btn1.layer.borderColor = kFF8700Color.CGColor;
        }else if ([model.NamingStatusName isEqualToString:@"已到"]){
            [btn1 setTitleColor:k1168E6Color forState:UIControlStateNormal];
            btn1.layer.borderWidth = 0.5f;
            btn1.layer.borderColor = k1168E6Color.CGColor;
            
        }else if ([model.NamingStatusName isEqualToString:@"未到"]){
            [btn1 setTitleColor:kRedColor forState:UIControlStateNormal];
            btn1.layer.borderWidth = 0.5f;
            btn1.layer.borderColor = kRedColor.CGColor;
            
        }
    }else{
        //MemberList.ClockStatus=null&&MemberList.IsNamingEnable=true:显示”已到“、”未到“、”请假“三个按钮；
        if (kIsEmptyString(model.ClockStatus) && model.IsNamingEnable) {
            //已到
            UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn1 setBackgroundColor:k1168E6Color];
            [btn1 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [btn1 setTitle:@"已到" forState:UIControlStateNormal];
            btn1.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
            btn1.titleLabel.textAlignment = NSTextAlignmentCenter;
            [btn1 addTarget:self action:@selector(codeAction:) forControlEvents:UIControlEventTouchUpInside];
            btn1.layer.cornerRadius = 2.f;
            btn1.clipsToBounds = YES;
            [self.bgView addSubview:btn1];
            [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(30);
                make.height.mas_equalTo(18);
                make.left.mas_equalTo(self.bgView).offset(4);
                make.centerY.mas_equalTo(self.bgView);
            }];
            
            //未到
            UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn2 setBackgroundColor:k1168E6Color];
            [btn2 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [btn2 setTitle:@"未到" forState:UIControlStateNormal];
            btn2.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
            btn2.titleLabel.textAlignment = NSTextAlignmentCenter;
            [btn2 addTarget:self action:@selector(codeAction:) forControlEvents:UIControlEventTouchUpInside];
            btn2.layer.cornerRadius = 2.f;
            btn2.clipsToBounds = YES;
            [self.bgView addSubview:btn2];
            [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(30);
                make.height.mas_equalTo(18);
                make.center.mas_equalTo(self.bgView);
            }];
            
            
            //请假
            UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn3 setBackgroundColor:k1168E6Color];
            [btn3 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [btn3 setTitle:@"请假" forState:UIControlStateNormal];
            btn3.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
            btn3.titleLabel.textAlignment = NSTextAlignmentCenter;
            [btn3 addTarget:self action:@selector(codeAction:) forControlEvents:UIControlEventTouchUpInside];
            btn3.layer.cornerRadius = 2.f;
            btn3.clipsToBounds = YES;
            [self.bgView addSubview:btn3];
            [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(30);
                make.height.mas_equalTo(18);
                make.centerY.mas_equalTo(self.bgView);
                make.right.mas_equalTo(self.bgView).offset(-4);
            }];
            
        }
        //MemberList.ClockStatus!=null&&MemberList.IsNamingEnable=true:显示”已到“、”未到“两个按钮；
        if (!kIsEmptyString(model.ClockStatus) && model.IsNamingEnable){
            UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn1 setBackgroundColor:k1168E6Color];
            [btn1 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [btn1 setTitle:@"已到" forState:UIControlStateNormal];
            btn1.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
            btn1.titleLabel.textAlignment = NSTextAlignmentCenter;
            [btn1 addTarget:self action:@selector(codeAction:) forControlEvents:UIControlEventTouchUpInside];
            btn1.layer.cornerRadius = 2.f;
            btn1.clipsToBounds = YES;
            [self.bgView addSubview:btn1];
            [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(30);
                make.height.mas_equalTo(18);
                make.left.mas_equalTo(self.bgView).offset(4);
                make.centerY.mas_equalTo(self.bgView);
            }];
            
            
            UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn2 setBackgroundColor:k1168E6Color];
            [btn2 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [btn2 setTitle:@"未到" forState:UIControlStateNormal];
            btn2.titleLabel.font = [UIFont boldSystemFontOfSize:10.f];
            btn2.titleLabel.textAlignment = NSTextAlignmentCenter;
            [btn2 addTarget:self action:@selector(codeAction:) forControlEvents:UIControlEventTouchUpInside];
            btn2.layer.cornerRadius = 2.f;
            btn2.clipsToBounds = YES;
            [self.bgView addSubview:btn2];
            [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(30);
                make.height.mas_equalTo(18);
                make.center.mas_equalTo(self.bgView);
            }];
        }
    }
}

/**
 请假
 */
- (void)btn1ApplyAction{
    if (self.memberBlockOne) {
        self.memberBlockOne(self.model);
    }
}

/**
 //MemberList.ClockStatus=null&&MemberList.IsNamingEnable=true:显示”已到“、”未到“、”请假“三个按钮；
 */

- (void)codeAction:(UIButton *)sender{
    //根据text来判断点击的是哪一个按钮
    NSString *code = @"";
    NSString *text = sender.titleLabel.text;
    if ([text isEqualToString:@"已到"]) {
        code = @"1";
    }else if ([text isEqualToString:@"未到"]){
        code = @"2";
    }else if ([text isEqualToString:@"请假"]){
        code = @"3";
    }
    if (self.memberBlockTwo) {
        self.memberBlockTwo(code);
    }
}
@end
